package com.zhang.cart.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

public class CartVo {

    List<CartItem> items;
    /**
     * 商品总数量
     */
    Integer countNum;

    /**
     * 商品类型数量
     */
    Integer countType;

    /**
     * 商品总价
     */
    BigDecimal totalAmount=BigDecimal.valueOf(0);

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        /*所有商品的数量总和*/
        int count = 0;
        for (CartItem item : items) {
            count+=item.getCount();
        }
        return count;
    }

    public void setCountNum(Integer countNum) {
        this.countNum = countNum;
    }

    public Integer getCountType() {
        return countType;
    }

    public void setCountType(Integer countType) {
        this.countType = countType;
    }

    public BigDecimal getTotalAmount() {
        for (CartItem item : items) {
            totalAmount=totalAmount.add(item.getTotalPrice());
        }
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    @Override
    public String toString() {
        return "CartVo{" +
                "items=" + items +
                ", countNum=" + getCountNum() +
                ", countType=" + getCountType() +
                ", totalAmount=" + getTotalAmount() +
                '}';
    }
}
